home *** CD-ROM | disk | FTP | other *** search
- /*THIS C PROGRAM PROVIDES A SKELETON FOR YOUR SPECIAL PURPOSE
- PROGRAM WHICH OPENS AN INTEL HEX FILE, AND BREAKS IT INTO ITS
- COMPONENT PARTS*/
-
- #include "stdio.h"
- #define ERROR -1
- #define ENDFILE 0xff
- char infile[15];
- int infd,chsum,loadadd,nbytes;
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- int i;
- int last;
-
- if(argc!=2){
- printf("\nCalling Sequence:\nOFFLOAD filespec\n");
- exit(1);
- }
- move(argv[1]);
- if((infd=open(infile,0))==ERROR){
- printf("\nCannot Open:%s\n",infile);
- exit(1);
- }
- READ:chsum=0;
- while(inbyte()!=':');
- if((nbytes=hexb())==0)goto QUIT;
- /*
- printf("nbytes=%d\n",nbytes);
- */
- loadadd=(hexb()<<8)+hexb();
- /*
- printf("loadadd=%04x\n",loadadd);
- */
- hexb();
- for(i=0;i<nbytes;++i) oput(hexb());
- last=hexb();
- if(chsum&0xff){
- /*
- printf("i=%02x last=%02x chsum=%02x\n",i,last,chsum);
- */
- printf("\nRead Error\n");
- exit(1);
- }
- goto READ;
- QUIT:printf("\nLast Load Address:%04x\n",loadadd);
-
- }
- move(string)
- char string[];
- {
- int i;
- char c;
-
- for(i=0;(c=string[i])&&c!='.';++i) infile[i]=c;
- infile[i]='\0';
- strcat(infile,".HEX");
- }
- inbyte()
- {
- char c;
- while((c=getc(infd))=="\r"||c=='\n');
- /*
- putchar(c);
- */
- if(c==ENDFILE){
- printf("\nUnexpected End of File\n");
- exit(1);
- }
- return(c);
- }
- hexc()
- {
- /*
- int tem;
- tem=dumm();
- printf("%02x",tem);
- return(tem);
- }
- dumm()
- {
- */
- char c;
-
- c=inbyte();
- if((c>='0'&&c<='9')||(c>='A'&&c<='F'))
- return(c<='9'?c-'0':c-'7');
- printf("\nRead Error in Hex File\n");
- exit(1);
- }
- hexb()
- {
- int v;
-
- v=(hexc()<<4)+hexc();
- /*
- printf("hexb=%02x\n",v);
- */
- chsum=chsum-v;
- return(v);
- }
- oput(v)
- int v;
- {
- printf("@%04x=%02x\n",loadadd,v);
- ++loadadd;
- }